#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

void solve()
{
    int n,q;
    cin>>n>>q;
    vector<int> a(n+1,0);
    vector<int> pre(n+1,0);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        pre[i]=pre[i-1];
        if(a[i]%2==0 || (int)sqrt(a[i])==sqrt(a[i]))
        {
            pre[i]=pre[i-1]+1;
        }
    }
    while(q--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        cout<<pre[r]-pre[l-1]<<endl;
    }
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
